import type { UserInfo } from '/#/store';
import { store } from '/@/store';
import { defineStore } from 'pinia';

interface UserState {
    userInfo: Nullable<UserInfo>;
    token?: string;
    sessionTimeout?: boolean;
    lastUpdateTime: number;
}

interface GetUserInfoModel {
    userId: string | number;
    username: string;
    realName: string;
    avatar: string;
    desc?: string;
}

export const useUserStore = defineStore({
    id: 'app-user',
    state: (): UserState => ({
        userInfo: null,
        token: undefined,
        sessionTimeout: false,
        lastUpdateTime: 0
    }),
    getters: {},
    actions: {
        setToken(info: string | undefined) {
            this.token = info ? info : '';
        },
        async login(): Promise<GetUserInfoModel | null> {
            // save token
            this.setToken('token test');
            return null;
        }
    }
});

export function useUserStoreWithOut() {
    return useUserStore(store);
}
